package client.comm.baoding.ui.vm

import android.app.Application
import android.text.TextUtils
import androidx.lifecycle.MutableLiveData
import client.comm.commlib.network.data.JsonResult
import client.comm.commlib.network.data.Ret
import client.comm.commlib.toast.toast
import client.comm.baoding.ui.viewmodel.MiddleVm

class XgmmViewModel(app: Application) : MiddleVm(app) {
    val forgetRet = MutableLiveData<JsonResult<Ret>>()
    val isShowing = MutableLiveData<Boolean>()

    val passwordOld = MutableLiveData<String>()
    val password = MutableLiveData<String>()
    val passwordAgain = MutableLiveData<String>()
    val isShowPwdOld = MutableLiveData<Boolean>(false)
    val isShowPwd = MutableLiveData<Boolean>(false)
    val isShowPwdAgain = MutableLiveData<Boolean>(false)

    fun switchIsShowPwdOld() {
        isShowPwdOld.value = !isShowPwdOld.value!!
    }

    fun switchIsShowPwd() {
        isShowPwd.value = !isShowPwd.value!!
    }

    fun switchIsShowPwdAgain() {
        isShowPwdAgain.value = !isShowPwdAgain.value!!
    }

    /**
     */
    fun ok() {
        if (TextUtils.isEmpty(passwordOld.value) || TextUtils.isEmpty(password.value) || TextUtils.isEmpty(
                passwordAgain.value
            )
        ) {
            toast("所有不能为空")
            return
        }
        if (!password.value.equals(passwordAgain.value)) {
            toast("二次输入密码不一致")
            return
        }
//        repository.xgpwd(passwordOld.value!!, password.value!!, forgetRet, isShowing)

        hold({
            server.set_pwd(passwordOld.value!!, password.value!!, passwordAgain.value!!)
        }, {
            isShowing.value = true
        }, {
            forgetRet.value = it
        }, {}, {
            isShowing.value = false
        })
    }

}